package com.shuangti.community.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shuangti.community.entity.CommunityPostTbl;
import com.shuangti.community.service.CommunityPostService;
import com.shuangti.community.service.impl.CommunityPostServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/community")
public class CommunityController {

    @Autowired
    CommunityPostServiceImpl communityPostService;

    @PostMapping("/addPost")
    public Map<String,String> addPost(CommunityPostTbl communityPostTbl){
        Map<String,String> result = new HashMap<>();
        result.put("成功添加", String.valueOf(communityPostService.addPost(communityPostTbl)));

        return  result;
    }

    @GetMapping("/delPost/{id}")
    public Map<String,String> delPost(@PathVariable("id")Long post_id){
        Map<String,String> result = new HashMap<>();
        result.put("删除成功",String.valueOf(communityPostService.delPost(post_id)));

        return result;
    }

    @GetMapping("/getPosts")
    public List<CommunityPostTbl> getPosts(@RequestParam Integer user_id,
                                           @RequestParam(defaultValue = "0")Integer page,
                                           @RequestParam(defaultValue = "5")Integer count){


        return communityPostService.getPostsByUserId(user_id, page, count);
    }
}
